package com.ehome.poct.base.controller.log;

import com.ehome.core.util.BeanConvertUtil;
import com.ehome.poct.base.api.dto.log.LogUploadCallbackDTO;
import com.ehome.poct.base.api.dto.log.SyncLogCallbackDTO;
import com.ehome.poct.base.api.dto.log.TestDeviceSyncLogRecordDTO;
import com.ehome.poct.base.api.virtual.log.TestDeviceSyncLogRecordService;
import com.ehome.poct.base.api.vo.log.TestDeviceSyncLogRecordVO;
import com.ehome.web.controller.AbstractBaseController;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 设备日志同步记录表控制器
 *
 * @author 路飞
 * @Date 2021-12-22 11:26
 */
@Slf4j
@Api(tags = "设备日志同步记录表")
@RestController
@RequestMapping("/test_device_sync_log_record")
public class TestDeviceSyncLogRecordController extends AbstractBaseController<TestDeviceSyncLogRecordVO, TestDeviceSyncLogRecordDTO> {

    @Autowired
    TestDeviceSyncLogRecordService testDeviceSyncLogRecordService;

    @ApiOperation("日志清单列表")
    @ApiOperationSupport(author = "路飞", order = 1)
    @GetMapping("/log_list")
    public SyncLogCallbackDTO getSyncLogRecord(@RequestParam String sno) {
        SyncLogCallbackDTO syncLogRecord = testDeviceSyncLogRecordService.getSyncLogRecord(sno);
        return syncLogRecord;
    }

    @ApiOperation("日志同步回调")
    @ApiOperationSupport(author = "路飞", order = 2)
    @PostMapping("/sync_log_callback")
    public void syncLogCallback(@RequestBody SyncLogCallbackDTO dto){
        testDeviceSyncLogRecordService.syncLogCallback(dto);
    }

    @ApiOperation("日志上传回调")
    @ApiOperationSupport(author = "路飞", order = 3)
    @PostMapping("/log_upload_callback")
    public void logUploadCallback(@RequestBody LogUploadCallbackDTO dto){
        testDeviceSyncLogRecordService.logUploadCallback1(dto);
        testDeviceSyncLogRecordService.logUploadCallback2(dto);
    }

    @ApiOperation(value = "批量同步日志")
    @ApiOperationSupport(author = "路飞", order = 4)
    @PostMapping("/batch")
    public TestDeviceSyncLogRecordVO batchInsertSyncLog(@RequestBody List<TestDeviceSyncLogRecordDTO> list){
        return BeanConvertUtil.convertBean(testDeviceSyncLogRecordService.batchInsertSyncLog(list),TestDeviceSyncLogRecordVO.class);
    }
}
